package net.xdclass.service.impl;

import lombok.extern.slf4j.Slf4j;
import net.xdclass.manager.ProductManager;
import net.xdclass.model.ProductDO;
import net.xdclass.service.ProductService;
import net.xdclass.vo.ProductVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 功能描述
 *
 * @author ASUS
 * @date 2024/08/31  15:26
 */
@Service
@Slf4j
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductManager productManager;
    @Override
    public List<ProductVO> list() {
        List<ProductDO> list = productManager.list();
        List<ProductVO> productVOS = list.stream().map(productDO -> beanProcess(productDO)).collect(Collectors.toList());
        return productVOS;
    }

    @Override
    public ProductVO detail(Long productId) {
        ProductDO productDO = productManager.detail(productId);
        ProductVO productVO = beanProcess(productDO);
        return productVO;
    }

    private ProductVO beanProcess(ProductDO productDO) {
        ProductVO productVO = new ProductVO();
        BeanUtils.copyProperties(productDO,productVO);
        return productVO;
    }
}
